package com.sansui.blog.service.impl;

import com.sansui.blog.dao.SysInfoDao;
import com.sansui.blog.pojo.SysConfig;
import com.sansui.blog.service.SysInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @name: SysInfoServiceImpl
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-04-04 13:49
 **/
@Service
public class SysInfoServiceImpl implements SysInfoService {

    @Autowired
    private SysInfoDao sysInfoDao;

    @Override
    public Map<String, Object> getSysInfo() {
        Map<String,Object> data = new HashMap<>(16);
        SysConfig sysConfig = sysInfoDao.getSysInfo();
        data.put("webname",sysConfig.getWebname());
        data.put("versionnum",sysConfig.getVersionNumber());
        data.put("weburl",sysConfig.getWeburl());
        return data;
    }


    @Override
    public SysConfig getSysSetting(){
        SysConfig sysConfig = sysInfoDao.getSysInfo();
        return sysConfig;
    }


    @Transactional
    @Override
    public Map<String, Object> saveSetting(SysConfig sysConfig) {
        Map<String,Object> data = new HashMap<>(16);
        try{
            sysConfig.setUpdateTime(new Date());
            sysInfoDao.saveSetting(sysConfig);
            data.put("code",200);
            data.put("msg","保存成功！");
        }catch (Exception e){
            data.put("code",400);
            data.put("msg","保存失败！");
        }

        return data;
    }

}
